﻿using System;
using System.Configuration;

namespace YN.Utils
{
    public class ConfigHelper
    {
        public static string GetConnectionString(string key)
        {
            try
            {
                return ConfigurationManager.ConnectionStrings[key].ConnectionString;
            }
            catch (NullReferenceException)
            {
                return null;
            }
        }

        //public static string GetConnectionString(int index)
        //{
        //    try
        //    {
        //        return ConfigurationManager.ConnectionStrings[index].ConnectionString;
        //    }
        //    catch (ArgumentOutOfRangeException)
        //    {
        //        return null;
        //    }
        //}

        public static string GetAppSetting(string key)
        {
            return ConfigurationManager.AppSettings[key];
        }

        public static string GetAppSetting(int index)
        {
            try
            {
                return ConfigurationManager.AppSettings[index];
            }
            catch (ArgumentOutOfRangeException)
            {
                return null;
            }
        }
    }
}
